/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: jse2302 - While3
 * <p>Powered by webrx On 2023-06-13 14:08:26
 * <p>Created by IntelliJ IDEA
 *
 * @author  webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class While3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
        //声明数组int[]
        int[] level = {10, 50, 100, 500, 1000, 2000, 5000, 10000, 10000, 10000};
        int max = level[rand.nextInt(level.length)];
        int num = rand.nextInt(1, max + 1);
        int n = 0;
        while (true) {
            ++n;
            if (n > 10) {
                System.out.printf("\033[31m游戏失败，你的游戏得 0 分。\033[0m%n");
                break;
            }
            System.out.printf("请输入数字[1-%d]:", max);
            int temp = 0;
            try {
                temp = sc.nextInt();
                if (temp < 1 || temp > max) {
                    --n;
                    System.out.printf("%n\033[33m输入错误，请重新输入。\033[0m%n");
                    continue;
                }
            } catch (Exception e) {
                if ("exit".equals(sc.next())) {
                    break;
                }
                --n;
                System.out.printf("%n\033[33m输入错误(必须输入整数数字)，请重新输入。\033[0m%n");
                continue;
            }
            if (temp > num) {
                System.out.printf("\033[31m%d、太大了。\033[0m%n", n);
            } else if (temp < num) {
                System.out.printf("\033[31m%d、太小了。\033[0m%n", n);
            } else {
                System.out.printf("\033[32m恭喜，你猜对了，你的游戏得 %d 分。\033[0m%n", (110 - n * 10));
                break;
            }
        }
        System.out.println("游戏结束");
    }
}
